package properties;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

/**
 * Properties相当于一个map,可以用map遍历的方法遍历
 */
public class Demo1 {
	public static void main(String[] args) {
		String value;
		String propName="number";
		Properties prop=new Properties();
        try{
            String path = System.getProperty("user.dir");
            prop.load(new FileInputStream(path + File.separator +"src"+File.separator+"test\\java\\properties\\"+ "storage.properties"));
            
            Set<Entry<Object, Object>> set=prop.entrySet();
            for (Entry<Object, Object> entry : set) {
				System.out.println(entry.getKey());
				System.out.println(entry.getValue());
			}
            
            Enumeration<Object> enums=prop.elements();
            while(enums.hasMoreElements()){
            	System.out.println(enums.nextElement());
            }
            
            value = prop.getProperty(propName);
            System.out.println("value = " + value);
        }catch(FileNotFoundException fnfe){
            System.out.println("file \"storage.properties\" not found");
            fnfe.printStackTrace();
        }catch(IOException ioe){
            ioe.printStackTrace();
        }
	}

}
